Imports agsXMPP
Imports agsXMPP.protocol.client
Imports agsXMPP.protocol.iq.roster

Namespace gtalkNotepad
	Public Class Contact

		Public Enum ContactStatus
			Active = 0
			Idle = 1
			Typing = 2
			Paused = 3
			ExtendedAway = 4
			Disconnected = 5
			Dnd = 6
		End Enum


		Private m_status As ContactStatus = ContactStatus.Disconnected
		Private m_threadId As String = ""
		Private m_isActive As Boolean = False
		Private m_jid As Jid

		Public ReadOnly Property UserName() As String
			Get
				Return m_jid.User
			End Get
		End Property

		Public ReadOnly Property Server() As String
			Get
				Return m_jid.Server
			End Get
		End Property

		Public ReadOnly Property Resource() As String
			Get
				Return m_jid.Resource
			End Get
		End Property

		Public ReadOnly Property Jid() As Jid
			Get
				Return m_jid
			End Get
		End Property

		Public Property IsActive() As Boolean
			Get
				Return m_isActive
			End Get
			Friend Set(ByVal value As Boolean)
				m_isActive = value
			End Set
		End Property

		Public Property ThreadId() As String
			Get
				If String.IsNullOrEmpty(m_threadId) Or Not m_isActive Then
					m_threadId = agsXMPP.util.Hash.Sha1Hash(Id.GetNextId() & m_jid.ToString())
					m_isActive = True
				End If
				Return m_threadId
			End Get
			Friend Set(ByVal value As String)
				m_threadId = value
			End Set
		End Property

		Public Property Status() As ContactStatus
			Get
				Return m_status
			End Get
			Friend Set(ByVal value As ContactStatus)
				m_status = value
				RaiseEvent OnStatusChange(Me, value)
			End Set
		End Property

		Public ReadOnly Property StatusText() As String
			Get
				Select Case m_status
					Case ContactStatus.Active : Return "Active"
					Case ContactStatus.Disconnected : Return "Disconnected"
					Case ContactStatus.Idle : Return "Idle"
					Case ContactStatus.Paused : Return "Paused"
					Case ContactStatus.Typing : Return "Typing"
					Case ContactStatus.Dnd : Return "Do Not Disturb"
					Case ContactStatus.ExtendedAway : Return "eX-Away"
				End Select
				Return "Disconnected"
			End Get
		End Property

		Public Event OnStatusChange(ByVal sender As Object, ByVal status As ContactStatus)

		Public Shared Operator =(ByVal left As Contact, ByVal right As Contact) As Boolean
			Return (left.UserName & left.Server & left.Resource = right.UserName & right.Server & right.Resource)
		End Operator

		Public Shared Operator <>(ByVal left As Contact, ByVal right As Contact) As Boolean
			Return (left.UserName & left.Server & left.Resource <> right.UserName & right.Server & right.Resource)
		End Operator

		Public Sub New(ByVal jid As Jid)
			m_jid = jid
		End Sub

		Public Overrides Function ToString() As String
			Return "[" & Me.StatusText & "] " & Me.UserName & "@" & Me.Server & ":" & Me.Resource
		End Function

	End Class
End Namespace
